<?php

$servername = "localhost";
$username = "test";
$password = "root123456";
$dbname = "test";


$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
echo "连接成功";

$filename = "test.sql";
$file_content = file_get_contents($filename);
if ($file_content === false) {
    die("无法读取SQL文件");
}

$commands = explode(';', $file_content);

foreach ($commands as $command) {
    $command = trim($command);
    if (!empty($command)) {
        if (!$conn->query($command)) {
            echo "执行SQL语句失败: ". $command. "<br>错误信息: ". $conn->error. "<br>";
        }
    }
}

//添加
$trucker_id = "A10011";
$Name = "张三";
$plateNumber = "B22222";
$email = "zhangsan@cam.com";
$route = "Route1";
$password = "123456";

$sql = "INSERT INTO trucker (trucker_id, last_name, first_name, plate_number, email, route, password) 
VALUES ('$trucker_id','$Name','$plateNumber','$email','$route','$password')";

if ($conn->query($sql) === TRUE) {
    echo "新增卡车司机成功{insert\_element\_0\_}";
} else echo "新增失败: " . $conn->error;
